/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Parallel;

import java.util.LinkedList;

/**
 *
 * @author zwirek
 */
public class Node {
    private char[] name;
    private boolean closed;
    private boolean closing;
    private LinkedList<Attribute> att;
    private LinkedList<Node> nodes;
    private String text;

    public Node(String name) {
        this.name = name.toCharArray();//CharArrPool.getCanonicalVersion(name.toCharArray());
//        this.name = CharArrPool.getCanonicalVersion(name.toCharArray());
        closed=false;
//        att = new LinkedList<Attribute>();
//        nodes = new LinkedList<Node>();
        text = "";
    }

    public void print() {
        System.out.println("Name: "+getName());
        if(att!=null){
            System.out.println("Att:");
            for(Attribute a:att){
                a.print();
            }
        }
        if(nodes!=null){
            System.out.println("Sons("+getName()+"):");
            for(Node n:getNodes()){
                n.print();
            }
        }
        System.out.println("==================");
    }

    /**
     * @return the name
     */
    public String getName() {
        return new String(name);
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
//        this.name = CharArrPool.getCanonicalVersion(name.toCharArray());
        this.name = name.toCharArray();//CharArrPool.getCanonicalVersion(name.toCharArray());
    }

    /**
     * @return the closed
     */
    public boolean isClosed() {
        return closed;
    }

    /**
     * @param closed the closed to set
     */
    public void setClosed(boolean closed) {
        this.closed = closed;
    }

    /**
     * @return the att
     */
    public LinkedList<Attribute> getAtt() {
        return att;
    }

    public void addAllAtt(LinkedList<Attribute> a){
        if(att==null){
            att=new LinkedList<Attribute>();
        }
        att.addAll(a);
    }

    /**
     * @param att the att to set
     */
    public void setAtt(LinkedList<Attribute> att) {
        this.att = att;
    }

    /**
     * @return the nodes
     */
    public LinkedList<Node> getNodes() {
        return nodes;
    }


    public void addNode(Node n){
        if(nodes==null){
            nodes = new LinkedList<Node>();
        }
        nodes.add(n);
    }


    public void addAllNodes(LinkedList<Node> n){
        if(nodes==null){
            nodes = new LinkedList<Node>();
        }
        nodes.addAll(n);
    }
    /**
     * @param nodes the nodes to set
     */
    public void setNodes(LinkedList<Node> nodes) {
        this.nodes = nodes;
    }

    /**
     * @return the text
     */
    public String getText() {
        return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }

    void addText(String toString) {
        text +="\n"+toString.intern();
    }

    /**
     * @return the closing
     */
    public boolean isClosing() {
        return closing;
    }

    /**
     * @param closing the closing to set
     */
    public void setClosing(boolean closing) {
        this.closing = closing;
    }

    @Override
    public String toString() {
        return new String(name)+" "+closed+" "+closing;
    }


}
